function [Ratio, TE] = inforatio(Asset, Benchmark)
%INFORATIO Compute the information ratio for one or more assets.
%	Given NUMSERIES assets with NUMSAMPLES returns for each asset in a
%	NUMSAMPLES x NUMSERIES matrix Asset and given a NUMSAMPLES vector of
%	benchmark returns in Benchmark, compute the information ratio and tracking
%	error for each asset relative to the Benchmark.
%
%	inforatio(Asset, Benchmark);
%	Ratio = inforatio(Asset, Benchmark);
%	[Ratio, TE] = inforatio(Asset, Benchmark);
%
% Inputs:
%	Asset - NUMSAMPLES x NUMSERIES matrix with NUMSAMPLES observations of
%		asset returns for NUMSERIES asset return series.
%	Benchmark - A NUMSAMPLES vector of returns for a benchmark asset. The
%		periodicity must be the same as the periodicity of Asset, e.g., if Asset
%		is monthly data, then Benchmark must be monthly returns.
%
% Outputs:
%	Ratio - A 1 x NUMSERIES row vector of information ratios for each series in
%		Asset. Any series in Asset with a tracking error of zero will have a NaN
%		value for its information ratio.
%	TE - A 1 x NUMSERIES row vector of tracking errors, i.e., the standard
%		devation of Asset relative to Benchmark returns, for each series.
%
% Notes:
%	NaN values in the data are ignored.
%
%	If a series in Asset is the Benchmark, its information ratio will be NaN
%	since its tracking error is 0.
%
%	The information ratio and the Sharpe ratio of an Asset versus a riskless
%	Benchmark (i.e., a Benchmark with standard deviation of returns equal to 0)
%	are equivalent. This equivalence is not necessarily true if the Benchmark is
%	risky.
%
% References:
%	[1] Richard C. Grinold and Ronald N. Kahn, Active Portfolio Management,
%		2nd. ed., McGraw-Hill, 2000.
%
%	[2] Jack Treynor and Fischer Black, "How to Use Security Analysis to Improve
%		Portfolio Selection," Journal of Business, Vol. 46, No. 1, January 1973,
%		pp. 66-86.
%
%	See also: sharpe, portalpha

%	Copyright 1995-2006 The MathWorks, Inc.
%	$Revision: 1.1.6.2 $   $Date: 2006/06/16 20:09:50 $

% Step 1 - check arguments

if nargin < 2 || isempty(Asset) || isempty(Benchmark)
	error('Finance:inforatio:MissingInputArg', ...
		'Missing required input arguments Asset or Benchmark.');
end

if ~isscalar(Asset) && isvector(Asset) && isa(Asset,'double')
	Asset = Asset(:);
	[m, n] = size(Asset);
elseif ndims(Asset) == 2 && min(size(Asset)) > 1 && isa(Asset,'double')
	[m, n] = size(Asset);
else
	error('Finance:inforatio:InvalidInputArg', ...
 		'Invalid format for Asset returns. Must be a vector or matrix.');
end

if ~isscalar(Benchmark) && isvector(Benchmark) && isa(Benchmark,'double')
	Benchmark = Benchmark(:);
	if size(Benchmark,1) ~= m
		error('Finance:inforatio:InconsistentDims', ...
			'Number of samples for Asset and Benchmark differ.');
	end
else
	error('Finance:inforatio:InvalidInputArg', ...
		'Invalid format for Benchmark returns. Must be a vector.');
end

% Step 2 - compute information ratio

for i = 1:n
	Asset(:,i) = Asset(:,i) - Benchmark;
end		
TE = nanstd(Asset, 1);
zDenom = max(Asset) == min(Asset);
Ratio(zDenom) = NaN;
Ratio(~zDenom) = 1 ./ TE(~zDenom);
Ratio = Ratio .* nanmean(Asset);
